package top.frsf.autocodegen.utils;

import top.frsf.autocodegen.entity.AutoDatasource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * JDBC Session 工厂
 *
 * @author FRSF
 * @since 2024/7/29 9:26
 */
public class JdbcSessionFactoryUtil {

    /**
     * 获取 JDBC 连接
     * @param datasource 数据源
     * @return Connection
     */
    public static Connection getSqlSessionFactory(AutoDatasource datasource) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        DriverManager.setLoginTimeout(5);
        return DriverManager.getConnection(datasource.getUrl(), datasource.getUsername(), datasource.getPassword());
    }
}
